if(!window.$){
	window.$ = {};
}
$.extend = function(obj, opt){
	if(obj == undefined){
		return opt;
	}
	for(var key in opt){
		if(!obj[key]){
			obj[key] = opt[key];
		}
//		switch(typeof(obj[key])){
//			case "object":
//				if(typeof(opt[key]) == "object"){
//					$.extend(obj[key], opt.key);
//				}else{
//					obj[key] = opt[key];
//				}
//				break;
//			default:
//				break;
//		}
	}
	return obj;
}
$.ajax = function(option){
	option = $.extend(option, {
		method:"GET",
		type:"json",
		headers:{},
		data:"",
		async:true,
		success:function(result){
		},
		error:function(result){
		}
	});
	var req = new XMLHttpRequest();
	req.open(option.method, option.url);
	req.onerror = function(){
		option.error.call(this, this.responseText)
	}
	req.onreadystatechange = function(){
		if(this.readyState == 4){
			if(this.status / 200 == 1){
				if(option.type == "json"){
					option.success.call(this, JSON.parse(this.response));
				}else if(option.type == "xml"){
					option.success.call(this, this.responseXML);
				}else{
					option.success.call(this, this.responseText);
				}
			}else{
				option.error.call(this, this.responseText)
			}
		}
	}
	
	for(var key in option.headers){
		req.setRequestHeader(key,option.headers[key]);
	}
	req.send(option.data);
	return req;
}